using System;
using System.Diagnostics;
using System.Numerics;
 
class Program
{
    static void Main()
    {
        int b = int.Parse(Console.ReadLine());
        int n = int.Parse(Console.ReadLine());
 
        long[] number = new long[n];
 
 
        for (int i = 0; i < n; i++)
        {
 
         number[i] = uint.Parse(Console.ReadLine());
 
        }
                 
        for (int i = 0; i < n; i++)
        {
          
            string a = Convert.ToString(number[i], 2);
 
            BigInteger length = a.Length;
 
            int zeros = 0;
            int ones = 0;
 
            for (int j = 0; j < length; j++)
            {
                if (BigInteger.Parse(a) % 10 == 0)
                {
                    zeros++;
                }
                else
                {
                    ones++;
                }
 
                a = a.Remove(a.Length - 1, 1);
            }
 
            if (b==0)
            {
                number[i] = (int)zeros;
            }
            else
            {
                number[i] = (int)ones;
            }
 
            Console.WriteLine(number[i]); 
        }
 
 
    }
}